<?php
require_once (APPLICATION_DIR."/application/model/Alumni_member_contact.php");
require_once (APPLICATION_DIR."/application/model/Alumni_member_personal.php");
require_once (APPLICATION_DIR."/application/model/Alumni_member_position_current.php");
require_once (APPLICATION_DIR."/application/model/Alumni_member_position_past.php");
require_once (APPLICATION_DIR."/application/model/Alumni_member_recommend.php");
require_once (APPLICATION_DIR."/application/model/Alumni_news.php");
require_once (APPLICATION_DIR."/application/model/Alumni_news_comment.php");
require_once (APPLICATION_DIR."/application/model/Industry.php");
require_once (APPLICATION_DIR."/application/model/Location.php");
require_once (APPLICATION_DIR."/application/model/Alumni_career.php");
require_once (APPLICATION_DIR."/application/model/Alumni_member_intake.php");
class AlumniMember
{	
	
	function changeGenderMember($p_arrInfo)
	{
		$objMemberPersonal = new DataObjects_Alumni_member_personal();
		$objMemberPersonal -> gender = $p_arrInfo['gender'];
		$objMemberPersonal -> whereAdd("id=" . $p_arrInfo['mb_id']);
		
		return $objMemberPersonal -> update(DB_DATAOBJECT_WHEREADD_ONLY);
	}
		
	function changeStatusMember($p_arrInfo)
	{
		$objMemberPersonal = new DataObjects_Alumni_member_personal();
		$objMemberPersonal -> status = $p_arrInfo['status'];
		$objMemberPersonal -> whereAdd("id=" . $p_arrInfo['mb_id']);
		
		return $objMemberPersonal -> update(DB_DATAOBJECT_WHEREADD_ONLY);
	}
		
	function getListIntake()
	{
		$objMemberIntake = new DataObjects_Alumni_member_intake();
		$objMemberIntake -> selectAdd();
		$objMemberIntake -> selectAdd("*");
		
		return $objMemberIntake -> fetchList();
	}
	
	function deleteMember($p_intMemberId)
	{
		$objMemberPersonal = new DataObjects_Alumni_member_personal();
		$objMemberPersonal -> id = $p_intMemberId;
		return $objMemberPersonal -> delete(); 		
	}
	function searchMember($p_arrInfo)
	{
		$objMember = new DataObjects_Alumni_member_personal();
		$objMember -> selectAdd();
		$objMember -> selectAdd("alumni_member_personal.*,
															alumni_member_intake.id as intake_id,
															alumni_member_intake.intake_name as intake_name
														");
		
		$objMember -> _join = " LEFT JOIN alumni_member_intake ON alumni_member_intake.id=alumni_member_personal.intake_id ";
		
		if ( $p_arrInfo['index'] != '-1' )
		{
			if ( $p_arrInfo['index'] == "username" )
				$objMember -> whereAdd("username LIKE '%" . trim($p_arrInfo['keyword']) . "%'");
			else if ( $p_arrInfo['index'] == "full_name" )
				$objMember -> whereAdd("full_name LIKE '%" . trim($p_arrInfo['keyword']) . "%'");
			else if ( $p_arrInfo['index'] == "class_name" )
				$objMember -> whereAdd("class_name LIKE '%" . trim($p_arrInfo['keyword']) . "%'");
		}
		if ( $p_arrInfo['gender'] != '-1' )
		{
			$objMember -> whereAdd("gender=" . $p_arrInfo['gender']);
		}
		if ( $p_arrInfo['intake_id'] != '-1' )
		{
			$objMember -> whereAdd("intake_id=" . $p_arrInfo['intake_id']);
		}
		if ( $p_arrInfo['status'] != '-1' )
		{
			$objMember -> whereAdd("status=" . $p_arrInfo['status']);
		}
		
		$objMember -> orderBy("created DESC");
		$objMember -> limit($p_arrInfo['start'], $p_arrInfo['limit']);
		$objMember -> find();
		
		return $objMember;
	}
	
	function updateMember($p_arrInfo)
	{
		$objMember = new DataObjects_Alumni_member_personal();
		if ( $p_arrInfo['password'] != '' )
			$objMember -> password = md5($p_arrInfo['password']);
		$objMember -> full_name = $p_arrInfo['full_name'];
		$objMember -> gender = $p_arrInfo['gender'];
		$objMember -> intake_id = $p_arrInfo['intake_id'];
		$objMember -> status = $p_arrInfo['status'];
		$objMember -> dob = $p_arrInfo['year_dob'] . "-" . $p_arrInfo['month_dob'] . "-" . $p_arrInfo['day_dob'] . " OO:00:00";
		$objMember -> whereAdd("id=" . $p_arrInfo['id']);
		return $objMember -> update(DB_DATAOBJECT_WHEREADD_ONLY);
	}
	
	function addMember($p_arrInfo)
	{
		$objMember = new DataObjects_Alumni_member_personal();
		$objMember -> username = $p_arrInfo['username'];
		$objMember -> password = md5($p_arrInfo['password']);
		$objMember -> full_name = $p_arrInfo['full_name'];
		$objMember -> gender = $p_arrInfo['gender'];
		$objMember -> intake_id = $p_arrInfo['intake_id'];
		$objMember -> status = $p_arrInfo['status'];
		$objMember -> dob = $p_arrInfo['year_dob'] . "-" . $p_arrInfo['month_dob'] . "-" . $p_arrInfo['day_dob'] . " OO:00:00";
		$objMember -> created = date("Y-m-d H:i:s");
		
		return $objMember -> insert();
	}
	
	function getInfoMemberId($p_intMemberId)
	{
		$objMember = new DataObjects_Alumni_member_personal();
		$objMember -> selectAdd();
		$objMember -> selectAdd("*");
		
		$objMember -> whereAdd("id=" . $p_intMemberId);
		$arrTmp = $objMember -> fetchList();
		
		if ( count($arrTmp) ) 
			return $arrTmp[0];
		else
			return false;
	}
	
	function getInfoMemberUsername($p_strUsername)
	{
		$objMember = new DataObjects_Alumni_member_personal();
		$objMember -> selectAdd();
		$objMember -> selectAdd("*");
		
		$objMember -> whereAdd("username='" . $p_strUsername . "'");
		$arrTmp = $objMember -> fetchList();
		
		if ( count($arrTmp) ) 
			return $arrTmp[0];
		else
			return false;
		
	}
}

?>